<?php use_helper('I18N'); ?>
<style type="text/css">
    p img {
        background: none repeat scroll 0 0 white;
        border: 1px solid #BBBBBB;
        margin: 7px 14px 7px 0;
        padding: 5px;
        height: 50px;
        /*width: 160px;*/
    }
</style>

<div id="content">

<!-- ========== CATEGORIES TABS ========= -->
<!-- ==================================== -->
<table id="contentMainWrapper" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td id="column-left" style="width: 215px;">
    <div style="width:215px;">
        <!--// bof: categories //-->
        <div class="box" id="categories" style="width:215px;">
            <div class="box-border">
                <div class="box-head">
                    <?php echo __('Categories') ?>
                </div>
                <div class="box-body">
                    <?php include_component('component', 'categoriesSideMenu') ?>
                </div>
            </div>
        </div>
        <!--// eof: categories //-->
        <!--// bof: specials //-->
        <div class="box" id="specials" style="width:215px;">
            <div class="box-border">
                <div class="box-head">
                    <a href="<?php echo url_for("/product/specialItem") ?>"><?php echo __('Specials') ?></a>
                </div>
                <div class="box-body">
                    <?php include_component('component', 'specialsSideMenu', array('param' => 'will implement for categoryType')) ?>
                </div>

            </div>
        </div>
        <!--// eof: specials //-->
    </div>
</td>

<td id="column-center" valign="top">

    <div class="column-center-padding">
        <div class="centerColumn" id="newProductsDefault">
            <?php if ($sf_flash->has('errorMsg')): ?>
                <?php echo $sf_flash->get('errorMsg') ?>
            <?php endif; ?>

            <h1 id="newProductsDefaultHeading">
                <?php
                    if ($query == Globals::LINK_PRODUCTS_NEW)
                echo __('New Products');
            else if ($query == Globals::LINK_PRODUCTS_SPECIAL)
                echo __('Specials');
            else if ($query == Globals::LINK_PRODUCTS_ALL)
                echo __('Products All');
            else if ($query == Globals::LINK_PRODUCTS_REVIEWS)
                echo __('Reviews');
                ?>
            </h1>


            <div id="sorter">
                <label for="disp_order"><?php echo __('Sort by') ?>: </label>

                <form name="sorter_form"
                      action="/product/index"
                      method="get">
                    <input name="p" value="<?php echo $query; ?>" type="hidden">
                    <select name="disp_order" onchange="this.form.submit();" id="disp_order">
                        <option value="<?php echo Globals::DISP_ORDER_PRODUCT_NAME ?>"><?php echo __('Product Name') ?></option>
                        <option value="<?php echo Globals::DISP_ORDER_PRICE_LOW_TO_HIGH ?>"><?php echo __('Price - low to high') ?></option>
                        <option value="<?php echo Globals::DISP_ORDER_PRICE_HIGH_TO_LOW ?>"><?php echo __('Price - high to low') ?></option>
                        <option value="<?php echo Globals::DISP_ORDER_DATE_ADDED_NEW_TO_OLD ?>"><?php echo __('Date Added - New to Old') ?></option>
                        <option value="<?php echo Globals::DISP_ORDER_DATE_ADDED_OLD_TO_NEW ?>"><?php echo __('Date Added - Old to New') ?></option>
                    </select>
                </form>
            </div>


            <br class="clearBoth">
                <?php
                    $param = "&p=" . $query;
            ?>
            <div id="newProductsDefaultListingTopNumber" class="navSplitPagesResult back"><?php echo __('Displaying') ?>
                <strong><?php echo $itemNumberFrom ?></strong> <?php echo __('to') ?>
                <strong><?php echo $itemNumberTo ?></strong>
                (<?php echo __('of %1% products', array('%1%' => "<strong>" . $totalItems . "</strong>")) ?>)
            </div>
            <div id="newProductsDefaultListingTopLinks" class="navSplitPagesLinks forward"> &nbsp;
                <a href="<?php echo url_for("/product/index?page=" . $pager->getFirstPage() . $param) ?>"
                   title=" <?php echo __('First Page') ?> ">[&lt;&lt;&nbsp;<?php echo __('First') ?>]</a>

                <a href="<?php echo url_for("/product/index?page=" . $pager->getPreviousPage() . $param) ?>"
                   title=" <?php echo __('Previous Page') ?> ">[&lt;&nbsp;<?php echo __('Prev') ?>]</a>
                &nbsp;&nbsp;
                <?php $links = $pager->getLinks();
                foreach ($links as $page):
                    echo ($page == $pager->getPage()) ? "<strong class='current'>" . $page . "</strong>"
                            : "<a href='" . url_for("/product/index?page=" . $page . $param) . "' title=' Page " . $page . "'>" . $page . "</a>";
                    echo "&nbsp;&nbsp;";
                endforeach; ?>

                <a href="<?php echo url_for("/product/index?page=" . $pager->getNextPage() . $param) ?>"
                   title=" <?php echo __('Next Page') ?> ">[<?php echo __('Next') ?>&nbsp;&gt;]</a>
                <a href="<?php echo url_for("/product/index?page=" . $pager->getLastPage() . $param) ?>"
                   title=" <?php echo __('Last Page') ?> ">[<?php echo __('Last') ?>&nbsp;&gt;&gt;]</a>
                &nbsp;
            </div>
            <br class="clearBoth">

            <table border="0" cellpadding="2" cellspacing="2" width="100%">
                <tbody>
                <?php foreach ($pager->getResults() as $cmsProduct):
                    $title = $cmsProduct->getProductName() . " #" . $cmsProduct->getProductCode();
                    if ($sf_user->getCulture() == "cn") {
                        $title = $cmsProduct->getProductNameCn() . " #" . $cmsProduct->getProductCode();
                    }
                    ?>

            <?php
            if ($query == Globals::LINK_PRODUCTS_REVIEWS) {
            ?>
                <div id="reviewsDefault" class="centerColumn">
                    <hr>
                    <div class="smallProductImage back">
                        <a href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>">
                            <img height="177" title="<?php echo $title; ?>" alt="<?php echo $title; ?>" src="/uploads/products/<?php echo $cmsProduct->getProductPhoto() ?>">
                        </a>
                    </div>

                    <div class="forward button-padding">
                        <div class="buttonRow">
                            <a href="<?php echo url_for("/product/review?id=" . $cmsProduct->getProductId()) ?>" style="text-decoration: none">
                                <img title=" Read the Review " alt="Read the Review"
                                    src="/images/buttons/arrow-right.png">&nbsp;<strong><?php echo __('Read the Review') ?></strong>
                            </a>
                        </div>
                        <div class="buttonRow">
                            <a href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>" style="text-decoration: none">
                                <img title=" Go To This Product's Detailed Information "
                                alt="Go To This Product's Detailed Information"
                                src="/images/buttons/arrow-right.png">&nbsp;<strong><?php echo __('Product Details') ?></strong>
                            </a>
                        </div>
                    </div>

                    <span class="name-type"><?php echo $title; ?></span>

                    <div class="rating">
                        <img width="104" height="19" alt="" src="/images/misc/stars_<?php echo $cmsProduct->getRate() ?>.gif">
                     </div>

                    <div class="content">
                        <?php echo $cmsProduct->getLastReviews() ?>
                    </div>

                    <?php
                        $timeStamp = strtotime($cmsProduct->getCreatedOn());
                        $dateString = date(Globals::FULL_DATETIME_FORMAT, $timeStamp);
                    ?>
                    <div class="bold"><?php echo __('Date Added') ?>: <?php echo $dateString ?>&nbsp;<br><br><?php echo __('By') ?>&nbsp;<?php echo $cmsProduct->getReviewsBy() ?></div>
                    <br class="clearBoth">
                </div>

            <?php } else { ?>
                <tr>
                    <td colspan="3">
                        <hr>
                    </td>
                </tr>
                <tr>
                    <td class="main" align="center" valign="top" width="30%">
                        <a href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>">
                            <img src="/uploads/products/<?php echo $cmsProduct->getProductPhoto() ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>" height="177" width="177"></a>
                        <br clear="all"><br clear="all">
                        <?php echo __('In Stock') ?>: <?php echo $cmsProduct->getTotalUnit() ?>
                        <br clear="all"><br clear="all">
                    </td>
                    <td colspan="2" class="main" valign="top">
                        <a class="name" href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>"><strong><?php echo $title; ?></strong></a>
                        <br clear="all"><br clear="all">
                        <?php echo __('Model') ?>: <?php echo $cmsProduct->getModal() ?>
                        <br clear="all"><br>
                        <?php echo __('Price') ?>:
                        <span class="productSpecialPrice">RM <?php echo number_format($cmsProduct->getPrice(), 2) ?></span>
                        <?php if ($cmsProduct->getSpecialItem() == Globals::DB_YES && $cmsProduct->getPrice2() != null && $cmsProduct->getPrice2() != 0) { ?>
                        &nbsp;<span
                                class="normalprice">RM <?php echo number_format($cmsProduct->getPrice2(), 2) ?> </span>
                        &nbsp;&nbsp;
                        <?php } ?>

                        <br clear="all"><br>
                        <?php echo __('Weight') ?>: <?php echo $cmsProduct->getWeight() . " " . $cmsProduct->getUom() ?>
                        <br clear="all"><br clear="all">
                        <?php
                            $timeStamp = strtotime($cmsProduct->getCreatedOn());
                            $dateString = date(Globals::FULL_DATETIME_FORMAT, $timeStamp);
                        ?>
                        <?php echo __('Date Added') ?>: <?php echo $dateString ?>
                        <br clear="all"><br clear="all">
                        <a href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>"
                           style="text-decoration: none">
                            <img src="/images/buttons/arrow-right.png"
                                 alt="<?php echo __('Buy Now') ?>"
                                 title="<?php echo __('Buy Now') ?>">&nbsp;<strong><?php echo __('Buy Now') ?></strong></a>&nbsp;
                        <br><br clear="all">
                        <!--   fancy box image lookup  -->
                        <?php include_component('component', 'fancybox', array('param' => $cmsProduct->getProductId())) ?>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" class="main" valign="top">
                        <?php echo $cmsProduct->getProductShortDesc() ?>
                        <a href="<?php echo url_for("/product/item?id=" . $cmsProduct->getProductId()) ?>">
                            ... <?php echo __('more info') ?></a></td>
                </tr>
            <?php } endforeach; ?>
                </tbody>
            </table>

            <div id="newProductsDefaultListingBottomNumber" class="navSplitPagesResult back">Displaying
                <strong><?php echo $itemNumberFrom ?></strong> <?php echo __('to') ?>
                <strong><?php echo $itemNumberTo ?></strong>
                (<?php echo __('of %1% products', array('%1%' => "<strong>" . $totalItems . "</strong>")) ?>)
            </div>
            <div id="newProductsDefaultListingBottomLinks" class="navSplitPagesLinks forward">
                <a href="<?php echo url_for("/product/index?page=" . $pager->getFirstPage() . $param) ?>"
                   title=" <?php echo __('First Page') ?> ">[&lt;&lt;&nbsp;<?php echo __('First') ?>]</a>

                <a href="<?php echo url_for("/product/index?page=" . $pager->getPreviousPage() . $param) ?>"
                   title=" <?php echo __('Previous Page') ?> ">[&lt;&nbsp;<?php echo __('Prev') ?>]</a>
                &nbsp;&nbsp;
                <?php $links = $pager->getLinks();
                foreach ($links as $page):
                    echo ($page == $pager->getPage()) ? "<strong class='current'>" . $page . "</strong>"
                            : "<a href='" . url_for("/product/index?page=" . $page . $param) . "' title=' Page " . $page . "'>" . $page . "</a>";
                    echo "&nbsp;&nbsp;";
                endforeach; ?>

                <a href="<?php echo url_for("/product/index?page=" . $pager->getNextPage() . $param) ?>"
                   title=" <?php echo __('Next Page') ?> ">[<?php echo __('Next') ?>&nbsp;&gt;]</a>
                <a href="<?php echo url_for("/product/index?page=" . $pager->getLastPage() . $param) ?>"
                   title=" <?php echo __('Last Page') ?> ">[<?php echo __('Last') ?>&nbsp;&gt;&gt;]</a>
                &nbsp;
            </div>

            <div class="clear"></div>
            <!--eof content_center-->
        </div>
        <!-- BOF- BANNER #4 display -->
        <!-- EOF- BANNER #4 display -->
</td>
</tr>
</tbody>
</table>

</div>

<script type="text/javascript">
                <?php
                    echo "$('#disp_order').val('" . $sorting . "')";
                ?>
</script>